import { createSlice, PayloadAction } from "@reduxjs/toolkit";

// export const deviceSlice = createSlice<typeof data,>(data)

const showLogin: boolean = false;
const showRegister: boolean = false;

export const deviceSlice = createSlice({
  name: "device",
  initialState: {
    device: "unknown",
    token: "",
    showLogin,
    showRegister,
  },
  reducers: {
    updateRegister(state, action: PayloadAction<boolean>) {
      return {
        ...state,
        showRegister: action.payload,
      };
    },
    updateLogin(state, action: PayloadAction<boolean>) {
      return {
        ...state,
        showLogin: action.payload,
      };
    },
    updateToken: (state, action: PayloadAction<string>) => {
      return {
        ...state,
        token: action.payload,
      };
    },
    updateDevice: (state, action: PayloadAction<string>) => {
      // state.device = action.payload;
      return {
        ...state,
        device: action.payload,
      };
    },
  },
});

export const deviceReducer = deviceSlice.reducer;

export const { updateDevice, updateToken, updateLogin, updateRegister } =
  deviceSlice.actions;
